package xyf.p07.binsearch;

/**
 * ClassName: M1005_FindString
 * Description:
 * Author: xyf
 * Date: 9/7/22 7:05 PM
 * Version: 1.0
 **/
public class M1005_FindString
{
    public int findString(String[] words, String s)
    {
        int start = 0;

        int end = words.length - 1;

        while (start <= end)
        {
            int mid = start + (end - start) / 2;

            while (words[mid].equals("") && mid > start)
            {
                mid--;
            }

            if (words[mid].compareTo(s) == 0)
            {
                return mid;
            }
            else if (words[mid].compareTo(s) < 0)
            {
                start = mid + 1;
            }
            else
            {
                end = mid - 1;
            }
        }

        return -1;
    }
}